package com.attedu.jdbc.homework;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Scanner;

/**
 * @author tune_the last
 * @date 2025/11/3 - 19:36
 */
public class Homework3 {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8", "root", "ASD13579asd");
        String sql = "DELETE FROM user WHERE username = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        Scanner in = new Scanner(System.in);
        System.out.print("请输入要注销的用户:");
        preparedStatement.setString(1, in.nextLine());
        int i = preparedStatement.executeUpdate();
        if (i > 0){
            System.out.println("注销成功！");
        }else{
            System.out.println("该用户不存在");
        }
        connection.close();
    }
}
